package android.pot.com.smartcar.guidepage.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
import android.view.WindowManager;

public class CicleView extends View {
	
	
	/**
	 * VALUE_CICLE_NUM 					圈的数量
	 * VALUE_CICLE_RADIUS					圈的半径
	 * VALUE_CICLE_STROKE_WIDTH		圈的粗细
	 * VALUE_CICLE_FILL_COLOR			圈的颜色
	 */
	private int VALUE_CICLE_NUM=5;
	private final int VALUE_CICLE_RADIUS=12;
	private final int VALUE_CICLE_STROKE_WIDTH=1;
    private final int VALUE_CICLE_FILL_COLOR=Color.rgb(204, 204, 204); //绿色
//	private final int VALUE_CICLE_FILL_COLOR=Color.rgb(255, 255, 255);
	
	private int selectPos;

	public CicleView(Context context) {
		super(context);
	}

	public CicleView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public CicleView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
	}

	/**
	 * 要画图形，最起码要有三个对象： 1.颜色对象 Color 2.画笔对象 Paint 3.画布对象 Canvas
	 */

	@Override
	public void onDraw(Canvas canvas) {
		DrawCicleSolidByPos(canvas,selectPos);
		super.onDraw(canvas);
	}

	private Size getScreenSize(){
    		WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    		float width = getWidth();
    		float height = getHeight();
        Size size=new Size(width,height);
    		return size;
    }
	
	private void DrawCicleSolidByPos(Canvas canvas,int pos){
		Paint paint = new Paint();
		
		//抗锯齿
	    paint.setAntiAlias(true);  
		
		paint.setColor(VALUE_CICLE_FILL_COLOR);
		paint.setStrokeWidth(VALUE_CICLE_STROKE_WIDTH);
		Size size=getScreenSize();
		float cx =0;
		float cy =0;
		float radius = VALUE_CICLE_RADIUS;
		
		cy=(float) (size.h*0.5);
		for (int i = 1; i <=VALUE_CICLE_NUM; i++) {
			cx=size.w/(VALUE_CICLE_NUM+1)*i;

			if(pos==(i-1)){
				paint.setStyle(Paint.Style.FILL);
				RectF r2=new RectF();
				r2.left=cx;                                 //左边
				r2.top=radius;                                 //上边
				r2.right=cx+30;                                   //右边
				r2.bottom=radius;               //RectF对象
				canvas.drawRoundRect(r2,radius,radius,paint);
			}else{
				paint.setStyle(Paint.Style.STROKE);
				canvas.drawCircle(cx, cy, radius, paint);

			}
		}
	}
	
	
	/**
	 * user public method
	 * 
	 */
	public void setCicleSolid(int pos){
		this.selectPos=pos;
		invalidate();
	}
	
	public void setCicleNum(int size) {
		if(size!=0)
			VALUE_CICLE_NUM=size;
	}
	

	public static class Size {
		private float w;
		private float h;

		public Size(float w, float h) {
			super();
			this.w = w;
			this.h = h;
		}

	}
	
}
